package com.mxgraph.examples.swing;

//import TableDemo;
import com.mxgraph.examples.swing.editor.DatabaseConnectivity;
import com.mxgraph.examples.swing.editor.SnmpGet;
import com.mxgraph.examples.swing.editor.SnmpWalk;
import javax.swing.*;

import java.awt.Container;
import java.awt.EventQueue;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Point;

//import TableDemo.MyTableModel;

//import TestTelnet.TableMouseListener;

//import com.mxgraph.examples.swing.editor.databaseConnectivity;
import com.mxgraph.examples.swing.editor.SnmpWalk;
import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxGeometry;
import com.mxgraph.model.mxGraphModel;
import com.mxgraph.swing.mxGraphComponent;
//import com..
import com.mxgraph.util.mxConstants;
import com.mxgraph.view.mxGraph;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
//import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;
import javax.swing.JLayeredPane;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.table.DefaultTableModel;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.Target;
import org.snmp4j.TransportMapping;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;

//import com.mxgraph.examples.swing.editor.EditorActions.deviceProperties;
public class DeviceInformation extends JPanel implements ActionListener {

    public JFrame frmDeviceInformation;
    private JTextField textField;
    private JTextField textField_1;
    Snmp snmp = null;
    String routerIP = null;
    String workstationMAC = null;
    String address = null;
    String idOfSelectedItem;
    static String sysType;
    //static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    //static final String DB_URL = "jdbc:mysql://127.0.0.1/pf";
    // Database credentials
    //static final String USER = "root";
    //static final String PASS = null;
    //Connection conn = null;
    Statement stmt = null;
    String strLine;
    String sysDescr;
    String sysName;
    String sysLoca;
    String syscont;
    String sysTime;
    String upTime;
    // for popup
    private JPopupMenu popupMenu;
    private JMenuItem devcprop;
    private JMenuItem locate;

    // String sysType=null;
    /**
     * Create the panel.
     *
     * @return
     */
    // public void SNMPManage(String add)
    public DeviceInformation(String value, boolean flag) {
        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa");
        idOfSelectedItem = value;
        // sysType=type;
        initialize();
    }

    /**
     * Launch the application.
     */
    /*
     public DeviceInformation(String add) {
     System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa");
     address = add;
     // initialize();
     }

     private void start() throws IOException {
     TransportMapping transport = new DefaultUdpTransportMapping();
     snmp = new Snmp(transport);
     // Do not forget this line!
     transport.listen();
     }

     public String getAsString(OID oid) throws IOException {
     ResponseEvent event = get(new OID[] { oid });
     return event.getResponse().get(0).getVariable().toString();
     }

     public ResponseEvent get(OID oids[]) throws IOException {
     PDU pdu = new PDU();
     for (OID oid : oids) {
     pdu.add(new VariableBinding(oid));
     }
     pdu.setType(PDU.GET);
     ResponseEvent event = snmp.send(pdu, getTarget(), null);
     if (event != null) {
     return event;
     }
     throw new RuntimeException("GET timed out");
     }

     private Target getTarget() {
     Address targetAddress = GenericAddress.parse(address);
     CommunityTarget target = new CommunityTarget();
     target.setCommunity(new OctetString("d@ere@d"));
     target.setAddress(targetAddress);
     target.setRetries(2);
     target.setTimeout(1500);
     target.setVersion(SnmpConstants.version2c);
     return target;
     }
     */
    /**
     * Create the application.
     */
    public DeviceInformation() {

        initialize();

    }

    /**
     * Initialize the contents of the frame.
     */
    public void initialize() {
        try {
            //deviceProperties b = new deviceProperties();
            System.out.println();
            // DeviceInformation client = new
            // DeviceInformation("udp:10.100.2.1/161");

            /*
             * String sysDescr = client.getAsString(new OID("1.3.6.1.2.1.1.6"));
             * String sysName = client.getAsString(new
             * OID("1.3.6.1.2.1.1.5.0")); String sysLoca =
             * client.getAsString(new OID("1.3.6.1.2.1.1.6.0")); String syscont
             * = client.getAsString(new OID("1.3.6.1.2.1.1.4.0")); String
             * sysTime = client.getAsString(new OID(".1.3.6.1.2.1.25.1.2"));
             */

            frmDeviceInformation = new JFrame();

            frmDeviceInformation.setResizable(false);
            frmDeviceInformation.setAlwaysOnTop(true);
            frmDeviceInformation.setBounds(100, 100, 450, 300);
            frmDeviceInformation
                    .setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

            JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
            frmDeviceInformation.getContentPane().add(tabbedPane,
                    BorderLayout.CENTER);

            JLayeredPane layeredPane_3 = new JLayeredPane();
            tabbedPane.addTab("General", null, layeredPane_3, null);

            JLabel lblInfo = new JLabel("Information");
            lblInfo.setBounds(137, 11, 81, 19);
            layeredPane_3.add(lblInfo);

            JLabel lblType = new JLabel("Type:");
            lblType.setBounds(37, 41, 62, 14);
            layeredPane_3.add(lblType);

            JLabel lblName = new JLabel("Name:");
            lblName.setBounds(37, 66, 74, 14);
            layeredPane_3.add(lblName);

            JLabel lblLocation = new JLabel("Location:");
            lblLocation.setBounds(37, 92, 74, 14);
            layeredPane_3.add(lblLocation);

            JLabel lblContact = new JLabel("Contact Person Name/pid:");
            lblContact.setBounds(37, 119, 130, 14);
            layeredPane_3.add(lblContact);

            JLabel lblMac = new JLabel("MAC Address:");
            lblMac.setBounds(37, 144, 95, 14);
            layeredPane_3.add(lblMac);

            JLabel lblIp = new JLabel("IP Address:");
            lblIp.setBounds(37, 169, 95, 14);
            layeredPane_3.add(lblIp);

            JButton btnOK = new JButton("OK");
            btnOK.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    OKButtonActionPerformed(evt);
                }
            });
            btnOK.setBounds(70, 194, 62, 23);
            layeredPane_3.add(btnOK);

            JButton btnCancel = new JButton("Cancel");
            btnCancel.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    CancelButtonActionPerformed(evt);
                }
            });
            btnCancel.setBounds(200, 194, 74, 23);
            layeredPane_3.add(btnCancel);
            if (idOfSelectedItem.startsWith("Switch")) {
                // routerIP = idOfSelectedItem;
                sysType = "Switch";

                String x = (String) idOfSelectedItem;
                // String x= (String) v10;
                System.out.println(x.replace("[", ""));
                x = x.replace("Switch_", "");
                // System.out.println( x.replace("]",""));
                // String j;
                // j=x.replace("]","");
                // System.out.println(j);
                routerIP = x;
                frmDeviceInformation.setTitle("Device Information of "
                        + routerIP + ".");
                System.out.println("DeviceInfobefore");
                SnmpGet snmpGet = new SnmpGet("udp:"
                        + routerIP + "/161", "d@ere@d", SnmpConstants.version2c);
                //DeviceInformation client = new DeviceInformation("udp:"
                //		+ routerIP + "/161");
                System.out.println("DeviceInfoafter");
                // client.start();
                snmpGet.start();
                // Class.forName("com.mysql.jdbc.Driver");
                System.out.println("Test1");
                // conn = (Connection) DriverManager.getConnection(DB_URL, USER,
                // PASS);
                System.out.println("Connected database successfully...");
                // STEP 4: Execute a query

                // stmt = conn.createStatement();
                // String sqlr =
                // ("SELECT mac FROM locationlog WHERE switch LIKE '" +j+ "' ");
                // System.out.println(sqlr);
                // ResultSet ru = stmt.executeQuery(sqlr);
                workstationMAC = " ";
                // while(ru.next())
                // {
                // Retrieve by column name
                // workstationMAC = ru.getString("mac");
                // System.out.print("MAC: " + workstationMAC);
                // }

                System.out.println("udp:" + routerIP + "/161");
                sysDescr = snmpGet.getAsString(new OID("1.3.6.1.2.1.1.6"));
                System.out.println("124");
                sysName = snmpGet.getAsString(new OID("1.3.6.1.2.1.1.5.0"));
                sysLoca = snmpGet.getAsString(new OID("1.3.6.1.2.1.1.6.0"));
                syscont = snmpGet.getAsString(new OID("1.3.6.1.2.1.1.4.0"));
                sysTime = snmpGet.getAsString(new OID(".1.3.6.1.2.1.25.1.2"));
                upTime  = snmpGet.getAsString(new OID(".1.3.6.1.2.1.1.3"));
            } else if (idOfSelectedItem.startsWith("Workplace")) {
                // workstationMAC = idOfSelectedItem;
                String x = (String) idOfSelectedItem;
                // String x= (String) v10;
                System.out.println(x.replace("[", ""));
                x = x.replace("Workplace_", "");
                workstationMAC = x;
                frmDeviceInformation.setTitle("Device Information of "
                        + workstationMAC + ".");
                sysType = "Workplace";
                //Class.forName("com.mysql.jdbc.Driver");
                System.out.println("Connecting to a selected database...");
                //conn = (Connection) DriverManager.getConnection(DB_URL, USER,
                //		PASS);
                System.out.println("Connected database successfully...");
                // STEP 4: Execute a query
                System.out.println("Creating statement...");

                //stmt = conn.createStatement();
                stmt = DatabaseConnectivity.generateStatement();
                String sql = ("SELECT computername FROM node WHERE mac LIKE '"
                        + workstationMAC + "'");
                String sqlq = ("SELECT pid FROM node WHERE mac LIKE '"
                        + workstationMAC + "'");
                System.out.println(sql);
                System.out.println(sqlq);
                ResultSet rs = stmt.executeQuery(sql);
                while (rs.next()) {
                    // Retrieve by column name
                    sysName = rs.getString("computername");
                    System.out.print("Name: " + sysName);
                }
                ResultSet rt = stmt.executeQuery(sqlq);
                while (rt.next()) {
                    // Retrieve by column name
                    syscont = rt.getString("pid");
                    System.out.print("Contact Person: " + syscont);
                }
                stmt.close();
            }
            else if (idOfSelectedItem.startsWith("Server")) {
              frmDeviceInformation.setTitle("Device Information of "
                        + idOfSelectedItem + ".");
                sysType = "Server";
                String[] splitServer = idOfSelectedItem.split("_");
                stmt = DatabaseConnectivity.generateStatement();
                String sql = ("SELECT sysname,contactpersonuid,syslocation,mac FROM packetfence_server_info WHERE ip LIKE '"
                        + splitServer[1] + "'");
                try{
                ResultSet rs = stmt.executeQuery(sql);
                while (rs.next()) {
                    // Retrieve by column name
                    sysName = rs.getString("sysname");
                    sysLoca = rs.getString("syslocation");
                    syscont = rs.getString("contactpersonuid");
                    workstationMAC = rs.getString("mac");
                    System.out.print("Name: " + sysName);
                routerIP = splitServer[1];}}catch(Exception e){}
               
                stmt.close();
            }
                        else if (idOfSelectedItem.startsWith("Printer")) {
              frmDeviceInformation.setTitle("Device Information of "
                        + idOfSelectedItem + ".");
                sysType = "Printer";
                String[] splitServer = idOfSelectedItem.split("_");
                stmt = DatabaseConnectivity.generateStatement();
                String sql = ("SELECT sysname,contactpersonuid,syslocation,mac FROM packetfence_printer_info WHERE ip LIKE '"
                        + splitServer[1] + "'");
                try{
                ResultSet rs = stmt.executeQuery(sql);
                while (rs.next()) {
                    // Retrieve by column name
                    sysName = rs.getString("sysname");
                    sysLoca = rs.getString("syslocation");
                    syscont = rs.getString("contactpersonuid");
                    workstationMAC = rs.getString("mac");
                    System.out.print("Name: " + sysName);
                routerIP = splitServer[1];}
               }catch(Exception e){}
                stmt.close();
            }
                        else if (idOfSelectedItem.startsWith("Firewall")) {
              frmDeviceInformation.setTitle("Device Information of "
                        + idOfSelectedItem + ".");
                sysType = "Firewall";
                String[] splitServer = idOfSelectedItem.split("_");
                stmt = DatabaseConnectivity.generateStatement();
                String sql = ("SELECT sysname,contactpersonuid,syslocation,mac FROM node WHERE packetfence_firewall_info LIKE '"
                        + splitServer[1] + "'");
                try{
                ResultSet rs = stmt.executeQuery(sql);
                while (rs.next()) {
                    // Retrieve by column name
                    sysName = rs.getString("sysname");
                    sysLoca = rs.getString("syslocation");
                    syscont = rs.getString("contactpersonuid");
                    workstationMAC = rs.getString("mac");
                    System.out.print("Name: " + sysName);
                routerIP = splitServer[1];}
               }catch(Exception e){}
                stmt.close();
            }
                        else if (idOfSelectedItem.startsWith("Router")) {
              frmDeviceInformation.setTitle("Device Information of "
                        + idOfSelectedItem + ".");
                sysType = "Router";
                String[] splitServer = idOfSelectedItem.split("_");
                stmt = DatabaseConnectivity.generateStatement();
                String sql = ("SELECT sysname,contactpersonuid,syslocation,mac FROM node WHERE packetfence_router_info LIKE '"
                        + splitServer[1] + "'");
                try{
                ResultSet rs = stmt.executeQuery(sql);
                while (rs.next()) {
                    // Retrieve by column name
                    sysName = rs.getString("sysname");
                    sysLoca = rs.getString("syslocation");
                    syscont = rs.getString("contactpersonuid");
                    workstationMAC = rs.getString("mac");
                    System.out.print("Name: " + sysName);
                    routerIP = splitServer[1];
                }
               }catch(Exception e){}
                stmt.close();
            }
            System.out.println(sysType);

            JLabel lblTypetext = new JLabel(sysType);
            lblTypetext.setBounds(192, 36, 130, 19);
            layeredPane_3.add(lblTypetext);

            JLabel lblNametext = new JLabel(sysName);
            lblNametext.setBounds(192, 66, 133, 19);
            layeredPane_3.add(lblNametext);

            JLabel lblLocationtext = new JLabel(sysLoca);
            lblLocationtext.setBounds(192, 87, 133, 19);
            layeredPane_3.add(lblLocationtext);

            JLabel lblContacttext = new JLabel(syscont);
            lblContacttext.setBounds(192, 114, 199, 19);
            layeredPane_3.add(lblContacttext);

            JLabel lblMacAddress = new JLabel(workstationMAC);
            lblMacAddress.setBounds(192, 139, 133, 19);
            layeredPane_3.add(lblMacAddress);

            JLabel lblIpAddress = new JLabel(routerIP);
            lblIpAddress.setBounds(192, 164, 130, 19);
            layeredPane_3.add(lblIpAddress);

            //JLayeredPane layeredPane_2 = new JLayeredPane();
            //tabbedPane.addTab("Security", null, layeredPane_2, null);

            //JLabel lblNewLabel_7 = new JLabel("Community Strings");
            //lblNewLabel_7.setBounds(142, 11, 113, 14);
            //layeredPane_2.add(lblNewLabel_7);

            //JRadioButton rdbtnRadio = new JRadioButton("Defaults");
           // rdbtnRadio.setBounds(45, 32, 109, 23);
           // layeredPane_2.add(rdbtnRadio);

           // JTextArea txtrNetworkMonitoringSystem = new JTextArea();
           // txtrNetworkMonitoringSystem.setEnabled(false);
           // txtrNetworkMonitoringSystem
           //         .setText("Network Monitoring System will use the factory \r\ndefault community strings or any additional \r\ncommunity strings specified when this devices\r\nsubnet was last discovered.");
            //txtrNetworkMonitoringSystem.setBounds(34, 55, 373, 76);
            //layeredPane_2.add(txtrNetworkMonitoringSystem);

           // JRadioButton rdbtnSpecify = new JRadioButton("Specify");
            //rdbtnSpecify.setBounds(45, 128, 109, 23);
            //layeredPane_2.add(rdbtnSpecify);

           // JLabel lblRead = new JLabel("Read:");
            //lblRead.setBounds(80, 158, 74, 14);
           // layeredPane_2.add(lblRead);

           // textField = new JTextField();
           // textField.setBounds(183, 156, 113, 17);
           // layeredPane_2.add(textField);
           // textField.setColumns(10);

           // JLabel lblWrite = new JLabel("Write:");
           // lblWrite.setBounds(80, 183, 46, 14);
           // layeredPane_2.add(lblWrite);

           // textField_1 = new JTextField();
           // textField_1.setColumns(10);
           // textField_1.setBounds(183, 181, 113, 17);
           // layeredPane_2.add(textField_1);

           // JButton btnOk = new JButton("OK");
           // btnOk.addActionListener(new java.awt.event.ActionListener() {
           //     public void actionPerformed(java.awt.event.ActionEvent evt) {
            //        OKButtonActionPerformed(evt);
            //    }
           // });
           // btnOk.setBounds(65, 208, 66, 23);
           // layeredPane_2.add(btnOk);

         //   JButton btnCan = new JButton("Cancel");
         //   btnCan.addActionListener(new java.awt.event.ActionListener() {
          //      public void actionPerformed(java.awt.event.ActionEvent evt) {
           //         CancelButtonActionPerformed(evt);
          //      }
          //  });
           // btnCan.setBounds(200, 209, 89, 23);
            //layeredPane_2.add(btnCan);

           // JLayeredPane layeredPane_1 = new JLayeredPane();
           // tabbedPane.addTab("Unit Information", null, layeredPane_1, null);

           // JLabel lblModel = new JLabel("Model:");
           // lblModel.setBounds(36, 11, 65, 14);
           // layeredPane_1.add(lblModel);

           // JLabel lblFirmware = new JLabel("Firmware:");
           // lblFirmware.setBounds(36, 36, 113, 14);
           // layeredPane_1.add(lblFirmware);

           // JLabel lblTime = new JLabel("Last Down Time:");
           // lblTime.setBounds(36, 61, 138, 14);
           // layeredPane_1.add(lblTime);

           // JLabel lblFrequency = new JLabel("Frequency of Down Time:");
           // lblFrequency.setBounds(36, 86, 155, 14);
           // layeredPane_1.add(lblFrequency);

           // JLabel lblHistory = new JLabel("History of Item:");
           // lblHistory.setBounds(36, 111, 138, 14);
           // layeredPane_1.add(lblHistory);

           // JTextArea textArea = new JTextArea();
          //  textArea.setEnabled(false);
          //  textArea.setEditable(false);
          //  textArea.setBounds(36, 125, 333, 64);
          //  layeredPane_1.add(textArea);
//
            /*
            JButton btnok = new JButton("OK");
            btnok.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    OKButtonActionPerformed(evt);
                }
            });
            btnok.setBounds(50, 200, 89, 23);
            layeredPane_1.add(btnok);

            JButton btncancel = new JButton("Cancel");
            btncancel.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    CancelButtonActionPerformed(evt);
                }
            });
            btncancel.setBounds(200, 200, 89, 23);
            layeredPane_1.add(btncancel);

            JLabel lblModelText = new JLabel("");
            lblModelText.setBounds(201, 11, 112, 20);
            layeredPane_1.add(lblModelText);

            JLabel lblFirmwareText = new JLabel("");
            lblFirmwareText.setBounds(200, 30, 113, 20);
            layeredPane_1.add(lblFirmwareText);

            JLabel lblTimeText = new JLabel(sysTime);
            lblTimeText.setBounds(200, 50, 113, 20);
            layeredPane_1.add(lblTimeText);

            JLabel lblFrequencyText = new JLabel("");
            lblFrequencyText.setBounds(201, 81, 112, 19);
            layeredPane_1.add(lblFrequencyText);

*/
      tabbedPane.addTab("Connectivity", createPanel());
            frmDeviceInformation.pack();

        } catch (Exception e) {
            System.out.println("Somesthing is wrong");
            System.out.println(e);
        }

    }

    private JPanel createPanel() {
        JPanel panel = new JPanel();
        DefaultTableModel model = new DefaultTableModel();
        String[] columnNames = {"Port no.", "Connected Device", "User name"};
        //model.setColumnIdentifiers(columnNames);
        System.out.println("ooooooooooooooooooooooo");
        JTable table = new JTable();
        table.setModel(model);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        table.setFillsViewportHeight(true);
        String portNo = "";
        String connectedDevice = "";
        String userName = "";
        String usage;
        String PortNumb[];
        String ConnectedSwitch[];
        String IPConnectedSwitch;
        Statement stmt;
        String stringSnmpVersion = null, SNMPCommunityRead = null;
        int intSnmpVersion = SnmpConstants.version2c;
        String lldpOID = "1.0.8802.1.1.2.1.4.2.1.3";
        String[] splitter = idOfSelectedItem.split("_");
        stmt = DatabaseConnectivity.generateStatement();
        ArrayList<String> connectedMAC = new ArrayList<String>();
        ArrayList<String> connectedPort = new ArrayList<String>();
        ArrayList<String> connectedPid = new ArrayList<String>();

        String sqllldp1 = ("SELECT SNMPVersion,SNMPCommunityRead FROM packetfence_switch_info WHERE ip LIKE '"
                + splitter[1] + "'");
        try {
            ResultSet rslldp = stmt.executeQuery(sqllldp1);
            if (rslldp.next()) {
                // Retrieve by column name
                stringSnmpVersion = rslldp.getString("SNMPVersion");
                SNMPCommunityRead = rslldp.getString("SNMPCommunityRead");
            } else {
                sqllldp1 = ("SELECT SNMPVersion,SNMPCommunityRead FROM packetfence_manuallyAddswitch_info WHERE ip LIKE '"
                        + splitter[1] + "'");
                rslldp = stmt.executeQuery(sqllldp1);
                while (rslldp.next()) {
                    // Retrieve by column name
                    stringSnmpVersion = rslldp.getString("SNMPVersion");
                    SNMPCommunityRead = rslldp.getString("SNMPCommunityRead");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        // final JTable table;
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        System.out.println("stringSnmpVersion" + stringSnmpVersion);
        try {
            if (stringSnmpVersion.equals("1")) {
                intSnmpVersion = SnmpConstants.version1;
            } else if (stringSnmpVersion.equals("3")) {
                intSnmpVersion = SnmpConstants.version1;
            } else {
                intSnmpVersion = SnmpConstants.version2c;
            }
        } catch (Exception e) {
        }
        List<String> output = new ArrayList<String>();
        System.out.println("dosnmpwalk ip:" + splitter[1]);
        SnmpWalk snmpWalk = new SnmpWalk(splitter[1], lldpOID, SNMPCommunityRead, intSnmpVersion);
        output = snmpWalk.doSnmpwalk();
        int connectedDevicesCounter = 1;
        System.out.println("output.size():" + output.size());
        for (int counter = 0; counter < output.size(); counter++) {
            String stringFormOID = output.get(counter);
            String[] OIDArray = stringFormOID.split("\\.");
            if (stringFormOID
                    .startsWith("1.0.8802.1.1.2.1.4.2.1.3")) {
                IPConnectedSwitch = OIDArray[OIDArray.length - 4]
                        + "."
                        + OIDArray[OIDArray.length - 3]
                        + "."
                        + OIDArray[OIDArray.length - 2]
                        + "." + OIDArray[OIDArray.length - 1];
                connectedMAC.add(IPConnectedSwitch);
                connectedPort.add(OIDArray[OIDArray.length - 8]);
                connectedPid.add("To Switch");
                System.out.println("IPConnectedSwitch:" + IPConnectedSwitch);

                // System.out.println("i:" + i);
                System.out.println("connectedDevicesCounter:" + connectedDevicesCounter);
            }
        }
        try {
            String columns[] = {"Port no.", "Connected Device", "User name"};

            //Statement stmt = null;
            //String[] connectedMAC = null;
            // conn = (Connection) DriverManager.getConnection(DB_URL,
            // USER,PASS);
            // String query = "select port from locationlog";
            System.out.println("kkkkkkkkkkkkkkkkkkkkkkkkkk");
            try {

                String sql = ("SELECT mac,port FROM locationlog WHERE switch LIKE '"
                        + splitter[1] + "' AND end_time IS NULL AND mac IS NOT NULL");
                System.out.println("aaaaaaaaaaaddress: " + address);
                stmt = DatabaseConnectivity.generateStatement();
                ResultSet resultset = stmt.executeQuery(sql);
                while (resultset.next()) {
                    connectedMAC.add(resultset.getString("mac"));
                    System.out.println("resultset.getString(\"mac\"):" + resultset.getString("mac"));
                    connectedPort.add(resultset.getString("port"));
                    System.out.println("resultset.getString(\"port\"):" + resultset.getString("port"));
                    //portArray =temp.split(",");
                    //ipCounter++;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            //System.out.println("connectedPort.get(0) :" + connectedPort.get(0));
            for (int i = 0; i < connectedPort.size(); i++) {
                try {
                    String sqlq = ("SELECT pid FROM node WHERE mac LIKE '"
                            + connectedMAC.get(i) + "'");
                    ResultSet resultset = stmt.executeQuery(sqlq);
                    while (resultset.next()) {
                        connectedPid.add(resultset.getString("pid"));
                        //connectedPort.add(resultset.getString("port"));
                        //portArray =temp.split(",");
                        //ipCounter++;
                    }
                } catch (Exception e) {
                }
            }
            System.out.println("$$$$$$$$$$");
            String[][] connectedDeviceInformation = new String[100][3];
            for (int i = 0; i < connectedPort.size(); i++) {
                //for(int j=0;j<3;j++){
                int j = 0;
                try {
                    connectedDeviceInformation[i][j++] = connectedMAC.get(i);
                    // System.out.println("connectedDeviceInformation[i][j]"+connectedDeviceInformation[i][j]);
                    connectedDeviceInformation[i][j++] = connectedPort.get(i);
                    //System.out.println("connectedDeviceInformation[i][j]"+connectedDeviceInformation[i][j]);
                    connectedDeviceInformation[i][j++] = connectedPid.get(i);
                    //System.out.println("connectedDeviceInformation[i][j]"+connectedDeviceInformation[i][j]);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //}
            }
            model.setDataVector(connectedDeviceInformation, columnNames);
            //new DatabaseConnectivity().Connectivity();
			/*ResultSet resultset = stmt.executeQuery(sql);
             int i = 0;
             if (resultset.next()) {
             portNo = resultset.getString("mac");
             connectedDevice = resultset.getString("port");
             //userName = rs.getString("class");
             model.addRow(new Object[] { portNo, connectedDevice, userName });
             table.getModel().setValueAt(portNo,i,0);
             table.getModel().setValueAt(connectedDevice,i,1);
				
             i++;

				
             }
             if (i < 1) {
             JOptionPane.showMessageDialog(null, "No Record Found", "Error",
             JOptionPane.ERROR_MESSAGE);
             }*/

            //String data[][] = { { resultset.getString("port") }

            //};

            /* Object data[][]={
             {"Tom",new Integer(20),"Male"}, {"Tina", new Integer(18),"Female"}, 
             {"Tina", new Integer(18), "Female"}, {"Tina", new Integer(18), "Female"}
             };
             */

            // JTable table = new JTable(data,columns);

            for (int c = 0; c < table.getColumnCount(); c++) {
                Class<?> col_class = table.getColumnClass(c);
                table.setDefaultEditor(col_class, null); // remove editor
            }

            //popupMenu = new JPopupMenu();
            //devcprop = new JMenuItem("Device property of selected item");
            //locate = new JMenuItem("Locate the selected item");

            //devcprop.addActionListener(this);
            //locate.addActionListener(this);

            //popupMenu.add(devcprop);
            //popupMenu.add(locate);

            // sets the popup menu for the table
            //table.setComponentPopupMenu(popupMenu);

            //table.addMouseListener(new TableMouseListener(table));

            panel.add(new JScrollPane(table) {
                @Override
                public Dimension getPreferredSize() {
                    return new Dimension(320, 240);
                }
            });

        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return panel;
    }

    public class TableMouseListener extends MouseAdapter {

        private JTable table;

        public TableMouseListener(JTable table) {
            this.table = table;
        }

        @Override
        public void mousePressed(MouseEvent event) {
            // selects the row at which point the mouse is clicked
            Point point = event.getPoint();
            int currentRow = table.rowAtPoint(point);
            table.setRowSelectionInterval(currentRow, currentRow);
        }
    }

    private void CancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // GEN-FIRST:event_CancelButtonActionPerformed
        // TODO add your handling code here:
        String cmd = evt.getActionCommand();
        if (cmd.equals("Cancel")) {
            frmDeviceInformation.dispose();
        }
    }

    private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // GEN-FIRST:event_CancelButtonActionPerformed
        // TODO add your handling code here:
        String cmd = evt.getActionCommand();
        if (cmd.equals("OK")) {
            frmDeviceInformation.dispose();
        }
    }

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // GEN-FIRST:event_CancelButtonActionPerformed
        // TODO add your handling code here:
        String cmd = evt.getActionCommand();
        if (cmd.equals("OK")) {
            frmDeviceInformation.dispose();
        }
    }

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // GEN-FIRST:event_CancelButtonActionPerformed
        // TODO add your handling code here:
        String cmd = evt.getActionCommand();
        if (cmd.equals("Cancel")) {
            frmDeviceInformation.dispose();
        }
    }

    private void OkButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // GEN-FIRST:event_CancelButtonActionPerformed
        // TODO add your handling code here:
        String cmd = evt.getActionCommand();
        if (cmd.equals("OK")) {
            frmDeviceInformation.dispose();
        }
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
    }
}
